package cn.fj.xiaowei.main.common.response.vo;

import cn.fj.xiaowei.main.common.response.en.RespStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;

/**
 * 通用响应结果类
 *
 * @param <T> 响应结果中的响应数据类型
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespResult<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 响应结果状态，true-成功；false-失败
     */
    private Boolean status;

    /**
     * 响应结果信息
     */
    private String msg;

    /**
     * 响应结果中的响应数据
     */
    private T data;

    public static <T> RespResult<T> success() {
        return new RespResult<>(RespStatusEnum.SUCCESS.getStatus(), RespStatusEnum.SUCCESS.getDesc(), null);
    }

    public static <T> RespResult<T> success(String message) {
        return new RespResult<>(RespStatusEnum.SUCCESS.getStatus(), message, null);
    }

    public static <T> RespResult<T> success(T data) {
        return new RespResult<>(RespStatusEnum.SUCCESS.getStatus(), RespStatusEnum.SUCCESS.getDesc(), data);
    }

    public static <T> RespResult<T> success(String message, T data) {
        return new RespResult<>(RespStatusEnum.SUCCESS.getStatus(), message, data);
    }

    public static <T> RespResult<T> fail() {
        return new RespResult<>(RespStatusEnum.FAIL.getStatus(), RespStatusEnum.FAIL.getDesc(), null);
    }

    public static <T> RespResult<T> fail(String message) {
        return new RespResult<>(RespStatusEnum.FAIL.getStatus(), message, null);
    }

    public static <T> RespResult<T> fail(T data) {
        return new RespResult<>(RespStatusEnum.FAIL.getStatus(), RespStatusEnum.FAIL.getDesc(), data);
    }

    public static <T> RespResult<T> fail(String message, T data) {
        return new RespResult<>(RespStatusEnum.FAIL.getStatus(), message, data);
    }

}

